package com.example.controller;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.extension.api.R;
import com.example.common.entity.TUserInfo;
import com.example.service.TUserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * (TUserInfo)表控制层
 *
 * @author 刘雨
 * @since 2024-11-25 17:36:57
 */
@RestController
@RequestMapping( "/tUserInfo" )
public class TUserInfoController {


    private final static Logger log = LoggerFactory.getLogger(TUserInfoController.class);

    /**
     * 服务对象
     */
    @Resource
    private TUserInfoService tUserInfoService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping( "/selectOne" )
    public TUserInfo selectOne(String id) {
        return this.tUserInfoService.queryById(id);
    }


    @GetMapping("/selectById/{id}")
    public TUserInfo selectById(@PathVariable String id){
        log.info("通过@PathVariable查询单个用户!");
        return this.tUserInfoService.queryById(id);
    }


    @GetMapping("/login")
    public R userLogin(String account, String password){
        log.info("通过TUserInfo用户登录!");
        TUserInfo user = this.tUserInfoService.login(account, password);
        if(user != null){
            return R.ok(user);
        }else{
            return R.failed("登录失败！请检查您的账户或密码是否正确。");
        }

    }

    @GetMapping("/export.user.do")
    public void exportEasyExcel(HttpServletResponse response){
        String exportTemplatesPath = "";
        String exportTemplatesFileName = ViewModelController.class
                .getResource("/").getPath() + System.currentTimeMillis() + ".xlsx";
        String exportTemplatesFileName_1 = ViewModelController.class
                .getResource("/").getPath() + "static/User基本信息模版.xlsx";

        log.info("模版文件地址："+ exportTemplatesFileName_1);
        log.info("模版文件地址："+ ViewModelController.class.getResource("/").getPath());

        //EasyExcel easyExcel = EasyExcel.write();

    }

}
